package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.SysFileInfoVo;
import com.ruoyi.business.service.ISysFileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 文件信息Controller
 *
 * @author Tellsea
 * @date 2023-02-08
 */
@Api(tags = "文件信息Controller")
@RestController
@RequestMapping("/business/fileInfo")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SysFileInfoController extends BaseController {

    private final ISysFileInfoService sysFileInfoService;

    @ApiOperation("查询文件信息列表")
    @PreAuthorize("@ss.hasPermi('business:fileInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<SysFileInfoVo> list(SysFileInfoVo entity) {
        return sysFileInfoService.queryList(entity);
    }

    @ApiOperation("查询文件信息所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(SysFileInfoVo entity) {
        return AjaxResult.success("查询成功", sysFileInfoService.queryAll(entity));
    }

    @ApiOperation("导出文件信息列表")
    @PreAuthorize("@ss.hasPermi('business:fileInfo:export')")
    @Log(title = "文件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFileInfoVo entity) {
        List<SysFileInfoVo> list = sysFileInfoService.queryAll(entity);
        ExcelUtil<SysFileInfoVo> util = new ExcelUtil<>(SysFileInfoVo.class);
        util.exportExcel(response, list, "文件信息数据");
    }

    @ApiOperation("获取文件信息详细信息")
    @PreAuthorize("@ss.hasPermi('business:fileInfo:query')")
    @GetMapping(value = "/getInfo/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId) {
        return AjaxResult.success("查询成功", sysFileInfoService.queryById(fileId));
    }

    @ApiOperation("新增文件信息")
    @PreAuthorize("@ss.hasPermi('business:fileInfo:add')")
    @Log(title = "文件信息", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody SysFileInfoVo entity) {
        return toAjax(sysFileInfoService.save(entity));
    }

    @ApiOperation("修改文件信息")
    @PreAuthorize("@ss.hasPermi('business:fileInfo:edit')")
    @Log(title = "文件信息", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody SysFileInfoVo entity) {
        return toAjax(sysFileInfoService.updateById(entity));
    }

    @ApiOperation("删除文件信息")
    @PreAuthorize("@ss.hasPermi('business:fileInfo:remove')")
    @Log(title = "文件信息", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds) {
        return toAjax(sysFileInfoService.removeByIds(Arrays.asList(fileIds)) ? 1 : 0);
    }
}
